package com.itheima.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.itheima.dto.GenderCountDto;
import com.itheima.mapper.CountMapper;
import com.itheima.service.CountService;
import com.itheima.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CountServiceImpl implements CountService {
    @Autowired
    private CountMapper countMapper;

    /**
     * 统计员工性别
     *
     * @return
     */
    @Override
    public List<GenderCountVo> count() {

        List<GenderCountVo> vo = countMapper.count();

        return vo;
    }

    /**
     * 统计员工职位
     *
     * @return
     */
    @Override
    public JopPeoCountVo jopCount() {

        List<XiaoVo> list = countMapper.jopCount();
        //使用stream流
        List<String> a = list.stream().map(vo -> vo.getName()).collect(Collectors.toList());
        List<Integer> b = list.stream().map(vo -> vo.getCount()).collect(Collectors.toList());
        return JopPeoCountVo.builder().jobList(a).dataList(b).build();
    }

    /**
     * 统计学员学历
     *
     * @return
     */
    @Override
    public List<StuDeqreeVo> stuDegree() {
       List<StuDeqreeVo> list =countMapper.stuDegree();
       return list;
    }

    /**
     * 统计班级人数
     *
     * @return
     */
    @Override
    public StuCountVo stuCount() {
         List<XiaoVo> list = countMapper.stuCount();
        List<String> name = CollUtil.getFieldValues(list, "name", String.class);
        List<Integer> count = CollUtil.getFieldValues(list, "count", Integer.class);
        return StuCountVo.builder().clazzList(name).dataList(count).build();
    }
}
